########
# Usage: Rscript cell_rel_cohort_corHeatmap.R HCC
# 传入参数： cohort = 'HCC'
#
########

library(corrplot)
library(RColorBrewer)

library(optparse)

option_list <- list(
  make_option("--b", default = "", type = "character", help = "blood mean file"),
  make_option("--t", default = "", type = "character", help = "tissue mean file"),
  make_option("--bo", default = "", type = "character", help = "blood output png file"),
  make_option("--to", default = "", type = "character", help = "tissue output png file")
)
opt <- parse_args(OptionParser(option_list = option_list))

#path='/home/D/lhy/exo/exoRBase/submit/cell_rel/'
#setwd(path)

Args = commandArgs()
cohort = Args[6]
print(cohort)

file.blood = opt$b
file.tissue = opt$t
outfile.blood = opt$bo
outfile.tissue = opt$to
w=8
h=32

data.cells = read.csv(file.blood, sep=',', header = TRUE, row.names=1)
data = round(data.cells, 3)*100
data=as.matrix(data)
pdf(outfile.blood, width=w, height=h)
par(pin=c(7000,7000))
col2 <- colorRampPalette(c("#77C034","#FFE4C4" ,"#C388FE"),alpha = TRUE)     
corrplot(as.matrix(data), 
             is.corr = FALSE,                                 
             addgrid.col = "grey80",                          
             outline = "orange",                             
             col = col2(20), 
             method = "circle",
             tl.col="black",           
             tl.srt=60,                
             tl.cex=0.8,               
             cl.length=5,              
             cl.pos = "n",             
             cl.ratio = 0.1,            
             cl.cex = 0.8,              
             addCoef.col="black",      
             rect.col=50,
             rect.lwd=50,
             number.cex=0.7,number.digits=1, number.font=1,
             xpd = T)  
dev.off()


data.cells = read.csv(file.tissue, sep=',', header = TRUE, row.names=1)
data = round(data.cells, 3)*100
data=as.matrix(data)
pdf(outfile.tissue, width=w, height=h)
par(pin=c(7000,7000))  
col2 <- colorRampPalette(c("#77C034","#FFE4C4" ,"#ABDDA4"),alpha = TRUE)     
corrplot(as.matrix(data), 
         is.corr = FALSE,                               
         addgrid.col = "grey80",                         
         outline = "orange",                             
         col = col2(20), 
         method = "circle",
         tl.col="black",           
         tl.srt=60,                
         tl.cex=0.8,               
         cl.length=5,              
         cl.pos = "n",             
         cl.ratio = 0.1,            
         cl.cex = 0.8,             
         addCoef.col="black",       
         rect.col=50,
         rect.lwd=50,
         number.cex=0.7,number.digits=1, number.font=1,
         xpd = T)  
dev.off()
